{extend  name="manage@public/layout" /}
{block name="content"}
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    
                    <div class="ibox-content">
                        <div class="table-responsive">
                            <div class="col-sm-12" style="padding:0;">
                                <div class="tabs-container">
                                    <ul class="nav nav-tabs">
                                        <li class="active"><a data-toggle="tab" href="#tab-1" aria-expanded="true"> 后台菜单</a>
                                        </li>
                                        <!-- <li class=""><a data-toggle="tab" href="#tab-2" aria-expanded="false">商户菜单</a>
                                        </li> -->
                                    </ul>
                                    <div class="tab-content">
                                        <div id="tab-1" class="tab-pane active">
                                            <div class="panel-body">
                                                <h5 style="margin:-5px 5px 0px !important;">
                                                    <button onClick="modaldemo(0)" style="padding:4px;margin-bottom:0 !important" type="button" class="btn btn-primary btn-xs">添加菜单</button>
                                                </h5>
                                                <div class="ibox-tools" style="top:-22px;">
                                                    <a class="collapse-link" onclick="location.replace(location.href);">
                                                        <i class="fa fa-refresh"></i>
                                                    </a>
                                                </div>
                                                <table class="table table-bordered">
                                                    <thead>
                                                        <tr>
                                                            <th>ID</th>
                                                            <th>菜单名称</th>
                                                            <th>节点</th>
                                                            <th>状态</th>
                                                            <th>排序</th>
                                                            <th>添加时间</th>
                                                            <th>操作</th>
                                                        </tr>
                                                    </thead>
                                                    <tbody>
                                                        {volist name="list" id="v"}
                                                        <tr>
                                                            <td>{$v.id}</td>
                                                            <td style="text-align: left;">{$v.lefthtml}{$v.title}</td>
                                                            <td>{$v.action|default='#'}</td>
                                                            <td><input data-type="zt" data-url="{:url('/manage/system/menu_type')}" {eq  name="v.type" value="2"}checked{/eq} data-id="{$v.id}" type="checkbox" class="js-switch"  /></td>
                                                            <td style="text-align: -webkit-center;"> <input name="sort" value="{$v.sort}" onblur="menusort({$v.id},this)" style="text-align:center;width:100px;" class="form-control"></td>
                                                            <td>{$v.create_time}</td>
                                                            <td>
                                                                <button onClick="menuEdit('编辑菜单','{:url('/manage/menu_edit',['pid'=>$v.id])}')" style="color: #1ab394;border: 1px solid #1ab394;" title="编辑" type="button" class="btn btn-sm bt-m-edit btn-white"><i class="fa fa-eye">&nbsp;编辑</i></button>
                                                                <a href="javascript:deleteMenu('{:url('/manage/meunDel',['pid'=>$v.id])}')" style="color: red;border: 1px solid red;" title="删除" type="button" class="btn btn-sm  btn-white"><i class="fa fa-eye">&nbsp;删除</i></a>
                                                            </td>
                                                        </tr>
                                                        {/volist}
                                                    </tbody>
                                                </table>
                                            </div>
                                        </div>
                                        <div id="tab-2" class="tab-pane">
                                            <div class="panel-body">
                                                <h5 style="margin:-5px 5px 0px !important;">
                                                    <button onClick="myModal(0)" style="padding:4px;margin-bottom:0 !important" type="button" class="btn btn-primary btn-xs">添加菜单</button>
                                                </h5>
                                                <div class="ibox-tools" style="top:-22px;">
                                                    <a class="collapse-link" onclick="location.replace(location.href);">
                                                        <i class="fa fa-refresh"></i>
                                                    </a>
                                                </div>
                                                <table class="table table-bordered">
                                                    <thead>
                                                        <tr>
                                                            <th>ID</th>
                                                            <th>菜单名称</th>
                                                            <th>节点</th>
                                                            <th>状态</th>
                                                            <th>排序</th>
                                                            <th>添加时间</th>
                                                            <th>操作</th>
                                                        </tr>
                                                    </thead>
                                                    <tbody>
                                                        {volist name="mch_list" id="v"}
                                                        <tr>
                                                            <td>{$v.id}</td>
                                                            <td style="text-align: left;">{$v.lefthtml}{$v.title}</td>
                                                            <td>{$v.action|default='#'}</td>
                                                            <td><input data-type="zt" data-url="{:url('/manage/system/menu_type')}" {eq  name="v.type" value="2"}checked{/eq} data-id="{$v.id}" type="checkbox" class="js-switch"  /></td>
                                                            <td style="text-align: -webkit-center;"> <input name="sort" value="{$v.sort}" onblur="menusort({$v.id},this)" style="text-align:center;width:100px;" class="form-control"></td>
                                                            <td>{$v.create_time}</td>
                                                            <td>
                                                                <button onClick="menuEdit('编辑菜单','{:url('/manage/menu_edit',['pid'=>$v.id])}')" style="color: #1ab394;border: 1px solid #1ab394;" title="编辑" type="button" class="btn btn-sm bt-m-edit btn-white"><i class="fa fa-eye">&nbsp;编辑</i></button>
                                                                <a href="javascript:deleteMenu('{:url('/manage/meunDel',['pid'=>$v.id])}')" style="color: red;border: 1px solid red;" title="删除" type="button" class="btn btn-sm bt-acc-del btn-white"><i class="fa fa-eye">&nbsp;删除</i></a>
                                                            </td>
                                                        </tr>
                                                        {/volist}
                                                    </tbody>
                                                </table>
                                            </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div> 
    <div class="modal  fade" id="myModal" tabindex="-1" role="dialog"  aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" style="margin-top:0;" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                    <h3 class="modal-title">添加菜单</h3>                  
                </div>
                <form class="form-horizontal">                   
                    <div class="ibox-content">
                            <div class="form-group">
                                <label class="col-sm-3 control-label">所属父级</label>
                                <div class="col-sm-8">                                                      
                                    <select name="pid" id="pid1" class="input-sm form-control input-s-sm inline">
                                        <option value="0">顶级菜单</option>
                                        {$mch_tree|raw}
                                    </select>                               
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">菜单名称</label>
                                <div class="col-sm-8">
                                    <input type="text" name="title" id="title1" placeholder="输入菜单名称" class="form-control"/>
                                </div>
                            </div>                      
                            <div class="hr-line-dashed"></div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">节点</label>
                                <div class="col-sm-8">
                                    <input type="text" name="action" id="action1" placeholder="路由地址" class="form-control"/>
                                </div>
                            </div>  
                            <div class="hr-line-dashed"></div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">图标</label>
                                <div class="col-sm-8">
                                    <input type="text" name="icon" id="icon1" placeholder="一级菜单有效" class="form-control"/>
                                    <span class="help-block m-b-none"> <a href="http://fontawesome.dashgame.com/" target="_black">选择图标</a> 如fa fa-user </span>
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                            <div class="form-group" style="margin-bottom:0;">
                                <label class="col-sm-3 control-label">排&nbsp;序</label>
                                <div class="col-sm-8">
                                    <input type="text" name="sort" id="sort1" value="0" placeholder="输入排序" class="form-control"/>
                                </div>
                            </div>
                        </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-primary btn-mch-menu"><i class="fa fa-save"></i> 保存</button>
                        <button type="button" class="btn btn-danger" data-dismiss="modal"><i class="fa fa-close"></i> 关闭</button>                    
                    </div>
                </form>
            </div>
        </div>
    </div>
    <div class="modal  fade" id="modal-demo" tabindex="-1" role="dialog"  aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" style="margin-top:0;" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                    <h3 class="modal-title">添加菜单</h3>                  
                </div>
                <form class="form-horizontal">                   
                    <div class="ibox-content">
                            <div class="form-group">
                                <label class="col-sm-3 control-label">所属父级</label>
                                <div class="col-sm-8">                                                      
                                    <select name="pid" id="pid" class="input-sm form-control input-s-sm inline">
                                        <option value="0">顶级菜单</option>
                                        {$tree|raw}
                                    </select>                               
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">菜单名称</label>
                                <div class="col-sm-8">
                                    <input type="text" name="title" id="title" placeholder="输入菜单名称" class="form-control"/>
                                </div>
                            </div>                      
                            <div class="hr-line-dashed"></div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">节点</label>
                                <div class="col-sm-8">
                                    <input type="text" name="action" id="action" placeholder="路由地址" class="form-control"/>
                                </div>
                            </div>  
                            <div class="hr-line-dashed"></div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">图标</label>
                                <div class="col-sm-8">
                                    <input type="text" name="icon" id="icon" placeholder="一级菜单有效" class="form-control"/>
                                    <span class="help-block m-b-none"> <a href="http://fontawesome.dashgame.com/" target="_black">选择图标</a> 如fa fa-user </span>
                                </div>
                            </div>
                            <input type="hidden" name="status" value="1">
                            <div class="hr-line-dashed"></div>
                            <div class="form-group" style="margin-bottom:0;">
                                <label class="col-sm-3 control-label">排&nbsp;序</label>
                                <div class="col-sm-8">
                                    <input type="text" name="sort" id="sort" value="0" placeholder="输入排序" class="form-control"/>
                                </div>
                            </div>
                        </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-primary btn-menu"><i class="fa fa-save"></i> 保存</button>
                        <button type="button" class="btn btn-danger" data-dismiss="modal"><i class="fa fa-close"></i> 关闭</button>                    
                    </div>
                </form>
            </div>
        </div>
    </div>
    {/block}
    {block name="script"}
    <script>
        function modaldemo() {

            $("#modal-demo").modal("show");
        }
        function myModal() {

            $("#myModal").modal("show");
        }
        function deleteMenu(url){
            parent.layer.confirm('确认删除吗？', {
                btn: ['确认','取消'], //按钮
                shade: false //不显示遮罩
            }, function(){
                parent.layer.closeAll('dialog');
                self.location.href =  url
            }, function(){
                parent.layer.msg('操作取消');
                return false;
            });
        }
        function menuEdit(title,url) {
            parent.layer.open({
                type: 2,
                title: title,
                shadeClose: true,
                shade: 0.4,
                area: ['600px', '550px'],
                content: url,
                //iframe层销毁后触发
                end:function(){
                    window.location.href = "/manage/menu";
                },
            });   
        }
        function menusort(id,obj){
            var sort = obj.value;
           $.post('/manage/menuSort',{id:id,sort:sort},function(result){
                parent.layer.msg(result.msg);
                setTimeout(function() {
                    window.location.reload();
                }, 1000)
           });
        }
        $(".btn-menu").click(function(){
            var pid = $("#pid option:selected").val();
            icon = $("#icon").val();
            action = $("#action").val();
            sort = $("#sort").val();
            title = $("#title").val();
            if(title == '' || title == '0'){
                parent.layer.msg("菜单名称不能为空");
                return false;
            }
            $.post('/manage/add_menu',{icon:icon,pid:pid,status:1,action:action,title:title,sort:sort},function(result){
                parent.layer.msg(result.msg);
                setTimeout(function() {
                    window.location.reload();
                }, 1000)
            })
        });
        $(".btn-mch-menu").click(function(){
            var pid = $("#pid1 option:selected").val();
            icon = $("#icon1").val();
            action = $("#action1").val();
            sort = $("#sort1").val();
            title = $("#title1").val();
            if(title == '' || title == '0'){
                parent.layer.msg("菜单名称不能为空");
                return false;
            }
            $.post('/manage/add_menu',{icon:icon,pid:pid,status:2,action:action,title:title,sort:sort},function(result){
                parent.layer.msg(result.msg);
                setTimeout(function() {
                    window.location.reload();
                }, 1000)
            })
        })
    </script>
    {/block}

